package com.wl.jetpackdemo.main

import android.content.Intent
import android.os.Bundle
import android.util.Log
import androidx.lifecycle.ViewModelProvider
import com.wl.jetpackdemo.base.BaseActivity
import com.wl.jetpackdemo.anylayer.AnyLayerActivity
import com.wl.jetpackdemo.banner.BannersActivity
import com.wl.jetpackdemo.base.BaseViewModel
import com.wl.jetpackdemo.databinding.ActivityMainBinding
import com.wl.jetpackdemo.base.network.NetRequestManager
import com.wl.jetpackdemo.bottomnav.BottomTabActivity
import com.wl.jetpackdemo.bottomtab.BottomTabLayoutActivity
import com.wl.wllite.rx.scheduler.SchedulerUtils
import io.reactivex.disposables.CompositeDisposable

class MainActivity : BaseActivity() {
    private lateinit var binding: ActivityMainBinding
    private var compositeDisposable = CompositeDisposable()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(binding.root)
        binding.listBtn.setOnClickListener {
            startActivity(Intent(this, BannersActivity::class.java))
        }

        binding.bottomNavBtn.setOnClickListener {
            startActivity(Intent(this, BottomTabActivity::class.java))
        }

        binding.bottomTabBtn.setOnClickListener {
            startActivity(Intent(this, BottomTabLayoutActivity::class.java))
        }

        binding.btnAnyLayer.setOnClickListener {
            startActivity(Intent(this, AnyLayerActivity::class.java))
        }

        val disposable = NetRequestManager.apiService().getBannersV2().compose(SchedulerUtils.ioToMain())
                .subscribe {
                    Log.d("WLTest", ">>>>>>")
                    for (item in it.data) {
                        Log.d("WLTest", "banner ${item.title}")
                    }
                }
        compositeDisposable.add(disposable)
    }

    override fun generateViewModel(): BaseViewModel? {
        return ViewModelProvider(this).get(MainViewModel::class.java)
    }

    private fun getViewModel() : MainViewModel {
        return getBaseViewModel()
    }

    override fun onDestroy() {
        super.onDestroy()
        if(!compositeDisposable.isDisposed)
            compositeDisposable.clear()
    }
}


